﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using SystemCenterSoa.ApiLibrary.PermissionsValidation;
using SystemCenterSoa.ApiProject.Area.SystemManager;
using SystemCenterSoa.DtoModel.Common;
using SystemCenterSoa.DtoModel.SystemManager;
using SystemCenterSoa.PoModel.SystemManager;
using SystemCenterSoa.Service.SystemManager;

namespace Net1905CoreDemo.ApiDemo.Controllers.BaseInfoManager
{
    [ApiModuleRelation("web_system_menu")]
    public class WebSystemMenuManagerController : SystemManagerBaseController
    {
        private WebSystemMenuService _webSystemMenuService;
        public WebSystemMenuManagerController(WebSystemMenuService webSystemMenuService)
        {
            _webSystemMenuService = webSystemMenuService;
        }

        [HttpGet]
        public ResultModel<List<WebSystemMenuPo>> GetModuleDbsAll()
        {
            try
            {
                var data = _webSystemMenuService.GetWebSystemMenuAll();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<WebSystemMenuPo>>(ex);
            }
        }
        [HttpGet]
        public ResultModel<List<WebSystemMenuDto>> GetWebSystemMenuViewsAll()
        {
            try
            {
                var data = _webSystemMenuService.GetWebSystemMenuViewsAll();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<WebSystemMenuDto>>(ex);
            }
        }
        [HttpGet]
        public ResultModel<bool> VMenuCode(string wmc)
        {
            try
            {
                var data = _webSystemMenuService.VMenuCode(wmc);

                return MyOk<bool>(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }

        [HttpPost]
        public ResultModel<bool> WSMAdd(WebSystemMenuPo wsm)
        {
            if (string.IsNullOrWhiteSpace(wsm.wm_code))
            {
                return MyFail<bool>("请输入菜单code");
            }
            if (!_webSystemMenuService.VMenuCode(wsm.wm_code))
            {
                return MyFail<bool>("菜单code已经被使用,请重新输入其他菜单Code");
            }


            wsm.creator_date = DateTime.Now;
            wsm.creator_name =LoginUser.user_name;
            try
            {
                var data = _webSystemMenuService.MenuAdd(wsm);
                return MyOk<bool>(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }


        [HttpGet]
        public ResultModel<WebSystemMenuDto> GetWebSystemMenuViewByCode(string wMCode)
        {
            if (string.IsNullOrWhiteSpace(wMCode))
            {
                return MyFail<WebSystemMenuDto>("参数错误, 缺少code参数");
            }
            try
            {
                var data = _webSystemMenuService.GetWebSystemMenuViewByCode(wMCode);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<WebSystemMenuDto>(ex);
            }

        }
        [HttpPost]
        public ResultModel<bool> WebSystemMenuDelete(string wmcode)
        {
            try
            {
                var data = _webSystemMenuService.WebSystemMenuDelete(wmcode);
                return MyOk<bool>(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }
        [HttpPost]
        public ResultModel<bool> WebSystemMenuUpdate(WebSystemMenuPo wsm)
        {
            try
            {
                var data = _webSystemMenuService.WebSystemMenuUpdate(wsm);
                return MyOk<bool>(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }

        [HttpGet]
        public ResultModel<List<WebSystemMenuDto>> GetUserWebSystemMenu()
        {
            try
            {
                var data = _webSystemMenuService.GetUserWebSystemMenus();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<WebSystemMenuDto>>(ex);
            }
        }
    }
}
